package com.doge.controller.admin;

import com.doge.bean.base.BaseRespVo;
import com.doge.bean.bo.order.OrderListBo;
import com.doge.bean.bo.order.ShipBO;
import com.doge.bean.vo.order.DetailOrderVo;
import com.doge.bean.vo.order.OrderResultVo;
import com.doge.exception.Param621Exception;
import com.doge.service.admin.order.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @program: doge
 * @description: 订单模块
 * @author: Mr.Jiang
 * @create: 2021-11-30 21:17
 **/
@RestController
@RequestMapping("admin/order")
public class OrderController {
    @Autowired
    OrderService orderService;
    @RequestMapping("list")
    public BaseRespVo list(@Valid OrderListBo orderListBo, ArrayList<String> timeArray){
        OrderResultVo orderResultVo=orderService.list(orderListBo);
        return BaseRespVo.ok(orderResultVo);
    }

    @RequestMapping("channel")
    public String channel(){
        String s="{\"errno\":0,\"data\":[{\"code\":\"ZTO\",\"name\":\"中通快递\"},{\"code\":\"YTO\",\"name\":\"圆通速递\"},{\"code\":\"YD\",\"name\":\"韵达速递\"},{\"code\":\"YZPY\",\"name\":\"邮政快递包裹\"},{\"code\":\"EMS\",\"name\":\"EMS\"},{\"code\":\"DBL\",\"name\":\"德邦快递\"},{\"code\":\"FAST\",\"name\":\"快捷快递\"},{\"code\":\"ZJS\",\"name\":\"宅急送\"},{\"code\":\"TNT\",\"name\":\"TNT快递\"},{\"code\":\"UPS\",\"name\":\"UPS\"},{\"code\":\"DHL\",\"name\":\"DHL\"},{\"code\":\"FEDEX\",\"name\":\"FEDEX联邦(国内件)\"},{\"code\":\"FEDEX_GJ\",\"name\":\"FEDEX联邦(国际件)\"}],\"errmsg\":\"成功\"}";
        return s;
    }

    @RequestMapping("detail")
    public BaseRespVo detail(Integer id){
        DetailOrderVo detailOrderVo=orderService.Detail(id);
        return BaseRespVo.ok(detailOrderVo);
    }

    @RequestMapping("refund")
    public BaseRespVo refund() throws Param621Exception {
        throw new Param621Exception("订单退款失败");
    }

    @RequestMapping("delete")
    public BaseRespVo delete (@RequestBody Map map, HttpServletRequest request){
        Integer orderId = (Integer) map.get("orderId");
        orderService.delete(orderId,request);
        return  BaseRespVo.error(402,"订单不能删除");
    }

    @RequestMapping("ship")
    public BaseRespVo ship(@RequestBody ShipBO shipBO, HttpServletRequest request){
        orderService.ship(shipBO,request);
        return BaseRespVo.ok();
    }
}
